<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>房屋编辑</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">

    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <link rel="shortcut icon" href="../img/favicon.ico">

    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="../plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="../plugins/morris/morris.css">
    <link rel="stylesheet" href="../plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <link rel="stylesheet" href="../plugins/datepicker/datepicker3.css">
    <link rel="stylesheet" href="../plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet" href="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="../plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="../plugins/treeTable/jquery.treetable.css">
    <link rel="stylesheet" href="../plugins/treeTable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="../plugins/select2/select2.css">
    <link rel="stylesheet" href="../plugins/colorpicker/bootstrap-colorpicker.min.css">
    <link rel="stylesheet" href="../plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../plugins/ionslider/ion.rangeSlider.css">
    <link rel="stylesheet" href="../plugins/ionslider/ion.rangeSlider.skinNice.css">
    <link rel="stylesheet" href="../plugins/bootstrap-slider/slider.css">
    <link rel="stylesheet" href="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
    <link rel="stylesheet" href="../plugins/bootstrap-start/css/star-rating.css" media="all" rel="stylesheet"
          type="text/css">
    <style>
        img[src=""],img:not([src]){
            opacity:0;
        }
    </style>
</head>

<body class="hold-transition skin-purple sidebar-mini">

<div class="wrapper">

    <!-- 头部+导航侧栏 -->
    <div id="page-head"></div>
    <!-- 头部+导航侧栏  /-->

    <!-- 内容区域 -->
    <div class="content-wrapper">

        <!-- 内容头部 -->
        <section class="content-header">
            <h1>
                发布房源
                <small>编辑信息</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="all-admin-index.html"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="all-order-manage-list.html">我的房屋</a></li>
                <li class="active">发布房源</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <!--房屋信息-->
            <div class="panel panel-default">
                <div class="panel-heading">房屋信息</div>
                <div class="row data-type">


                    <div class="col-md-2 title">房东姓名</div>
                    <div class="col-md-4 data text" id="houseOwner">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-user"></i>
                            </div>
                            <input type="text" id="userName" class="form-control pull-right" placeholder="请输入姓名"
                                   value="">

                        </div>

                    </div>

                    <div class="col-md-2 title">房屋地址</div>
                    <div class="col-md-4 data text" id="houseAddress">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-map-marker"></i>
                            </div>
                            <input type="text" id="userAddress" class="form-control pull-right" placeholder="请输入地址"
                                   value="">

                        </div>
                    </div>

                    <div class="col-md-12 data text" style="background-color: rgba(239,235,0,0.25) !important"></div>


                    <div class="col-md-2 title">楼层</div>
                    <div class="col-md-4 data text" id="houseUnitHeight">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-align-center"></i>
                            </div>
                            <input type="text" id="userUnitHeight" class="form-control pull-right" placeholder="请输入楼层"
                                   value="">

                        </div>
                    </div>

                    <div class="col-md-2 title">面积</div>
                    <div class="col-md-4 data text" id="houseArea">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-tag"></i>
                            </div>
                            <input type="text" id="userArea" class="form-control pull-right" placeholder="请输入面积"
                                   value="">

                        </div>
                    </div>

                    <div class="col-md-12 data text" style="background-color: rgba(139,239,0,0.25) !important"></div>

                    <div class="col-md-2 title">类型</div>
                    <div class="col-md-4 data text" id="houseType">

                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-bookmark"></i>
                            </div>
                            <input type="text" id="userType" class="form-control pull-right" placeholder="例：2室1厅1卫"
                                   value="">

                        </div>
                    </div>

                    <div class="col-md-2 title">户型</div>
                    <div class="col-md-4 data text" id="houseDwellingSize">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-home"></i>
                            </div>
                            <input type="text" id="userDwellingSize" class="form-control pull-right"
                                   placeholder="例：普通住宅" value="">

                        </div>
                    </div>

                    <div class="col-md-12 data text" style="background-color: rgba(239,0,227,0.25) !important"></div>

                    <div class="col-md-2 title">价格</div>
                    <div class="col-md-4 data text" id="housePrice">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-jpy"></i>
                            </div>
                            <input type="text" id="userPrice" class="form-control pull-right" placeholder="例：1500元/月"
                                   value="">

                        </div>
                    </div>

                    <div class="col-md-2 title">联系电话</div>
                    <div class="col-md-4 data text" id="houseTel">
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="glyphicon glyphicon-earphone"></i>
                            </div>
                            <input type="text" id="userTel" class="form-control pull-right" placeholder="请输入电话"
                                   value="">
                        </div>
                    </div>

                    <div class="col-md-12 data text " style="background-color: rgba(0,192,239,0.25) !important"></div>

                    <div class="col-md-2 title">发布方式</div>
                    <div class="col-md-10 data text">
                        <div class="form-group form-inline">
                            <div class="radio"><label><input id="userHouse1" type="radio" name="optionsRadios-a11"
                                                             value="1">
                                出租</label></div>
                            <div class="radio"><label><input id="userHouse2" type="radio" name="optionsRadios-a11"
                                                             value="2">出售</label>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-12 data text " style="background-color: rgba(239,0,48,0.25) !important"></div>


                    <div class="col-md-2 title rowHeight2x">房屋概况</div>
                    <div class="col-md-10 data  rowHeight2x" id="houseDescription">
                        <textarea class="form-control" id="userDescription" rows="3" placeholder="房屋详细介绍,最多输入200字"
                                  maxlength="200"></textarea>
                    </div>
                    <!--                    图片上传功能-->
                    <div>
                        <button href="javascript:void(0)" onclick="uploadPhoto()"  class="btn btn-success">选择图片</button>
                        <input type="file" id="photoFile"  style="display: none;" onchange="upload()">
                        <img id="preview_photo" class="img-thumbnail" src="" name="image" width="200px" height="200px">
                    </div>

                </div>
            </div>
            <!--房屋信息/-->

            <!--工具栏-->
            <div class="box-tools text-center">
                <button type="button" id="sendUserHouse" class="btn bg-maroon">保存</button>
                <button type="button" class="btn btn-info" onclick="history.back(-1);">返回</button>
            </div>
            <!--工具栏/-->

        </section>
        <!-- 正文区域 /-->

    </div>
    <!-- 内容区域 /-->

    <!-- 底部导航 -->
    <div id="page-footer"></div>
    <!-- 底部导航 /-->

</div>


<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="../plugins/jQueryUI/jquery-ui.min.js"></script>
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="../plugins/raphael/raphael-min.js"></script>
<script src="../plugins/morris/morris.min.js"></script>
<script src="../plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="../plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="../plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="../plugins/knob/jquery.knob.js"></script>
<script src="../plugins/daterangepicker/moment.min.js"></script>
<script src="../plugins/daterangepicker/daterangepicker.js"></script>
<script src="../plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
<script src="../plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="../plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script src="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="../plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="../plugins/fastclick/fastclick.js"></script>
<script src="../plugins/iCheck/icheck.min.js"></script>
<script src="../plugins/adminLTE/js/app.min.js"></script>
<script src="../plugins/treeTable/jquery.treetable.js"></script>
<script src="../plugins/select2/select2.full.min.js"></script>
<script src="../plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="../plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
<script src="../plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
<script src="../plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
<script src="../plugins/bootstrap-markdown/js/markdown.js"></script>
<script src="../plugins/bootstrap-markdown/js/to-markdown.js"></script>
<script src="../plugins/ckeditor/ckeditor.js"></script>
<script src="../plugins/input-mask/jquery.inputmask.js"></script>
<script src="../plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="../plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="../plugins/chartjs/Chart.min.js"></script>
<script src="../plugins/flot/jquery.flot.min.js"></script>
<script src="../plugins/flot/jquery.flot.resize.min.js"></script>
<script src="../plugins/flot/jquery.flot.pie.min.js"></script>
<script src="../plugins/flot/jquery.flot.categories.min.js"></script>
<script src="../plugins/ionslider/ion.rangeSlider.min.js"></script>
<script src="../plugins/bootstrap-slider/bootstrap-slider.js"></script>
<script src="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="../plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="../plugins/bootstrap-start/js/star-rating.js"></script>
<script>
    function uploadPhoto() {
        $("#photoFile").click();
    }

    /**
     * 上传图片
     */
    function upload() {
        if ($("#photoFile").val() == '') {
            return;
        }
        var formData = new FormData();
        formData.append('photo', document.getElementById('photoFile').files[0]);
        $.ajax({
            url:"/uploadPhoto",
            type:"post",
            data: formData,
            contentType: false,
            processData: false,
            success: function(data) {
                if (data.type == "success") {
                    console.log("图片上传后端数据响应成功！")
                    $("#preview_photo").attr("src", data.filepath+data.filename);
                    $("#preview_photo").attr("name",data.filename);

                } else {
                    alert(data.msg);
                }
            },
            error:function(data) {
                alert("上传失败")
            }
        });
    }
</script>
<script>
    $(document).ready(function () {
        //装入头部
        $('#page-head').load('public-head.html', null, function () {
            setSidebarActive("admin-create");
        });
        //装入尾部
        $('#page-footer').load('public-footer.html');
        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });


    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }


    $(document).ready(function () {
        $('#datepicker-a3').datepicker({
            autoclose: true,
            language: 'zh-CN'
        });
    });


    $(document).ready(function () {
        $('#datepicker-a6').datepicker({
            autoclose: true,
            language: 'zh-CN'
        });
    });
</script>

<script>
    $(function () {
        var userUuid = "";  //保存用户的uuid
        var userName = "";          //保存房东姓名
        var address = "";            //保存地址
        var unitHeight = "";      //保存楼层
        var area = "";           //保存面积
        var type = "";              //保存户型
        var dwellingSize = "";              //保存类型
        var price = "";             //保存价格
        var tel = "";           //保存电话号码
        var status = 0;             //房屋发布的状态，出售还是出租
        var description = "";       //房屋概况
        var houseImage = "";       //房屋概况

        //判断用户输入是否合法
        function isLegal() {
            if (userName === "") {
                alert("请输入房东的姓名");
                return false;
            }
            if (address === "") {
                alert("请输入地址");
                return false;
            }
            if (unitHeight === "") {
                alert("请输入楼层");
                return false;
            }
            if (area === "") {
                alert("请输入房屋面积");
                return false;
            }
            if (dwellingSize === "") {
                alert("请输入户型");
                return false;
            }
            if (type === "") {
                alert("请输入户型");
                return false;
            }
            if (price === "") {
                alert("请输入价格");
                return false;
            }
            if (tel === "") {
                alert("请输入电话");
                return false;
            }
            if (status === 0) {
                alert("请选择发布房屋的方式：出售/出租");
                return false;
            }
            if (description === "") {
                alert("请描述房屋详细信息");
                return false;
            }
            return true;
        }

        //处理房源发布类型的控件
        $("#userHouse1").on("click", function () {
            status = $(this).val();
        })
        $("#userHouse2").on("click", function () {
            status = $(this).val();
        })


        $("#sendUserHouse").on("click", function () {
            userName = $("#userName").val();                  //保存房东姓名
            address = $("#userAddress").val();                 //保存地址
            unitHeight = $("#userUnitHeight").val();        //保存楼层
            area = $("#userArea").val();                  //保存面积
            dwellingSize = $("#userDwellingSize").val();                    //保存面积
            type = $("#userType").val();                    //保存面积
            price = $("#userPrice").val();                   //保存价格
            tel = $("#userTel").val();                   //保存电话号码
            description = $("#userDescription").val();        //房屋发布的状态，出售还是出租
            houseImage = $("#preview_photo").attr("name");        //房屋图片名字
            Date.prototype.Format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1, //月份
                    "d+": this.getDate(), //日
                    "H+": this.getHours(), //小时
                    "m+": this.getMinutes(), //分
                    "s+": this.getSeconds(), //秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                    "S": this.getMilliseconds() //毫秒
                };
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            }
            var myDate = new Date().Format("yyyy-MM-dd HH:mm:ss");  //时间

            //先ajax的post请求发送给后台存储
            //先判断合法性
            if (isLegal()) {
                // alert("输入合法！");
                //包装成json数据
                var dataJson = {
                    "userUuid": userUuid,
                    "userName": userName,
                    "address": address,
                    "unitHeight": unitHeight,
                    "area": area,
                    "type": type,
                    "dwellingSize": dwellingSize,
                    "picture": "no",
                    "status": status,
                    "price": price,
                    "tel": tel,
                    "description": description,
                    "score": 5.0,
                    "createTime": myDate,
                    "updateTime": myDate,
                    "houseImage": houseImage,
                };
                //ajax请求,通过post返回给后台存储
                $.ajax({
                    url: "/all-order-create-house/house/insert",   //请求路径
                    type: "post",    //请求方式，这里应该用post，返回给后台分页是数据：当前页，每页的大小
                    data: JSON.stringify(dataJson),
                    contentType: "application/json;charset=UTF-8",
                    dataType: "json",  //设置接收到数据类型
                    success: function (data) {
                        alert("保存成功！");
                        // 处理分页数据
                        // console.log("房屋存储信息增加成功！");
                    },    //成功
                    error: function () {
                        console.log("房屋存储信息失败...")
                    }
                })
            }


        })


        //（！！！需要修改）获取当前用户的uuid
        $.ajax({
            url: "/all-order-manage-edit/message/user",   //请求路径
            type: "get",    //请求方式
            dataType: "json",  //设置接收到数据类型
            success: function (data) {
                // console.log("返回的留言信息:" + data);
                var jsonData = JSON.parse(data);
                // alert(jsonData);
                userUuid = jsonData.userUuid;
                // alert("uuid:"+userUuid);
                // 处理分页数据
            },    //成功
            error: function () {
                console.log("获取姓名失败...")
            }
        })


    })


</script>
</body>

</html>